package com.wooophone.mpyeah.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.wooophone.mpyeah.biz.OnLineStoreBiz;
import com.wooophone.mpyeah.dao.OnLineStoreDao;
import com.wooophone.mpyeah.entity.OnLineStore;
import com.wooophone.mpyeah.mapper.OnLineStoreMapper;

public class OnLineStoreDaoImpl implements OnLineStoreDao {
	Logger log = Logger.getLogger(OnLineStoreBiz.class);

	@Autowired
	OnLineStoreMapper onLineStoreMapper;

	public void setOnLineStoreMapper(OnLineStoreMapper onLineStoreMapper) {
		this.onLineStoreMapper = onLineStoreMapper;
	}

	@Override
	public OnLineStore save(OnLineStore obj) {
		onLineStoreMapper.save(obj);
		return obj;
	}

	@Override
	public int update(OnLineStore obj) {
		return onLineStoreMapper.update(obj);
	}

	@Override
	public int delete(String id) {
		return onLineStoreMapper.delete(id);
	}

	@Override
	public OnLineStore get(String id) {
		return onLineStoreMapper.get(id);
	}

	@Override
	public List<OnLineStore> list() {
		return onLineStoreMapper.list();
	}

	@Override
	public List<OnLineStore> list(int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return onLineStoreMapper.listByLimit(parameter);
	}

	@Override
	public int count() {
		return onLineStoreMapper.count();
	}

	@Override
	public List<OnLineStore> find(Map<String, Object> parameter) {
		return onLineStoreMapper.listByParameter(parameter);
	}

	@Override
	public List<OnLineStore> find(Map<String, Object> parameter, int offset,
			int limit) {
		parameter.put("limit", limit);
		parameter.put("offset", offset);
		return onLineStoreMapper.listByParameter(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return onLineStoreMapper.countByParameter(parameter);
	}

	@Override
	public int count(String keyword) {
		keyword = "%" + keyword + "%";
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("keyword", keyword);
		return onLineStoreMapper.countByKeyword(parameter);
	}

	@Override
	public List<OnLineStore> search(String keyword, int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("limit", limit);
		parameter.put("offset", offset);
		parameter.put("keyword", "%" + keyword + "%");
		return onLineStoreMapper.search(parameter);
	}

	public int countByBrandId(String brandId) {
		return onLineStoreMapper.countByBrandId(brandId);
	}

	@Override
	public List<OnLineStore> recommendOnLineStore(int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("limit", limit);
		parameter.put("offset", offset);
		return onLineStoreMapper.recommendOnLineStore(parameter);
	}

	@Override
	public List<OnLineStore> recommendOnLineStoreLimitLevel(int limitLevel,
			int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("limitLevel", limitLevel);
		parameter.put("limit", limit);
		parameter.put("offset", offset);
		return onLineStoreMapper.recommendOnLineStoreLimitLevel(parameter);
	}

	@Override
	public List<OnLineStore> recommendOnLineStore(int level, int offset,
			int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("level", level);
		parameter.put("limit", limit);
		parameter.put("offset", offset);
		return onLineStoreMapper.recommendOnLineStore(parameter);
	}

}
